package de.tu_darmstadt.gdi1.xcom.tests.testcases.students;

import static org.junit.Assert.*;

import java.util.HashMap;

import org.junit.Before;
import org.junit.Test;

import de.tu_darmstadt.gdi1.xcom.tests.adapters.XcomTestAdapterLevel1;

/**
 * 
 * Extension of the level1-correctness-tests, doors and switches as well as gamestates
 * are tested here as well.
 * 
 * @author Fabian Vogt, Lukas Schwoebel
 *
 */
public class ExtendedLevelCorrectnessTest {
	
	private XcomTestAdapterLevel1 testAdapter;
	
	private HashMap<String, Boolean> levels;
	
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		testAdapter = new XcomTestAdapterLevel1();
		levels = new HashMap<String, Boolean>();
		levels.put("" +
				"############\n" +
				"##...#######\n" +
				"##...##m.+##\n" +
				"###.###...##\n" +
				"###.####.###\n" +
				"#....##...##\n" +
				"#.........##\n" +
				"############\n" +
				"//{mobs}\n" +
				"//@;4;2;n;50;75;50;50;10\n" +
				"//@;2;5;n;50;75;50;50;10\n" +
				"//@;4;6;n;50;75;50;50;10\n" +
				"//Z;2;2;n;50;75;50;0;0\n" +
				"//Z;3;2;n;50;75;50;0;0\n" +
				"//Z;7;3;n;50;75;50;0;0\n" +
				"//Z;7;5;n;50;75;50;0;0\n" +
				"//Z;9;6;n;50;75;50;0;0\n" +
				"//{doors}\n" +
				"//1;4;8;4;c\n" +
				"//{gamedata}\n" +
				"//activeteam:@\n" +
				"//playedrounds:0\n" +
				"//maxrounds:2", true);
		levels.put("" +
				"####\n" +
				"#..#\n" +
				"##.#\n" +
				"#++#\n" +
				"#m.#\n" +
				"####\n" +
				"//{mobs}\n" +
				"//@;2;1;n;50;75;50;50;10\n" +
				"//Z;1;1;n;50;75;50;0;10\n" +
				"//{gamedata}\n" +
				"//activeteam:@\n" +
				"//playedrounds:0\n" +
				"//maxrounds:2", true);
		// invalid switch-->door combination
		levels.put("" +
				"####\n" +
				"#..#\n" +
				"##.#\n" +
				"####\n" +
				"//{mobs}\n" +
				"//@;1;1;n;50;75;50;50;10\n" +
				"//{doors}\n" +
				"//2;1;1;2;c", false);
		// player put on medikit
		levels.put("" +
				"####\n" +
				"#+.#\n" +
				"##.#\n" +
				"####\n" +
				"//{mobs}\n" +
				"//@;1;1;n;50;75;50;50;10\n" +
				"//{doors}\n" +
				"//1;2;2;1;c", false);
		// invalid gamestate - more than 0 turns need to be played!
		levels.put("" +
				"####\n" +
				"#..#\n" +
				"##.#\n" +
				"####\n" +
				"//{mobs}\n" +
				"//@;1;1;n;50;75;50;50;10\n" +
				"//{doors}\n" +
				"//0;0;2;1;c\n" +
				"//{gamedata}" +
				"//activeteam:@\n" +
				"//playedrounds:0\n" +
				"//maxrounds:0", false);
		// two switches go for the same door
		levels.put("" +
				"#######\n" +
				"#.m+###\n" +
				"#.....#\n" +
				"#####.#\n" +
				"#.....#\n" +
				"#++...#\n" +
				"#######\n" +
				"//{mobs}\n" +
				"//@;1;1;n;50;75;50;50;10\n" +
				"//Z;1;4;n;50;75;50;0;0\n" +
				"//{doors}\n" +
				"//4;1;5;3;c\n" +
				"//0;1;5;3;c\n" +
				"//{gamedata}\n" +
				"//activeteam:@\n" +
				"//playedrounds:1\n" +
				"//maxrounds:5", false);
		// redundant information - twice the same switch/door
		levels.put("" +
				"#######\n" +
				"#.m+###\n" +
				"#.....#\n" +
				"#####.#\n" +
				"#.....#\n" +
				"#++...#\n" +
				"#######\n" +
				"//{mobs}\n" +
				"//@;1;1;n;50;75;50;50;10\n" +
				"//Z;1;4;n;50;75;50;0;0\n" +
				"//{doors}\n" +
				"//4;1;5;3;c\n" +
				"//4;1;5;3;c\n" +
				"//{gamedata}\n" +
				"//activeteam:@\n" +
				"//playedrounds:1\n" +
				"//maxrounds:5", false);
		// player on closed door
		levels.put("" +
				"#######\n" +
				"#.m+###\n" +
				"#.....#\n" +
				"#####.#\n" +
				"#.....#\n" +
				"#++...#\n" +
				"#######\n" +
				"//{mobs}\n" +
				"//@;1;1;n;50;75;50;50;10\n" +
				"//Z;1;4;n;50;75;50;0;0\n" +
				"//{doors}\n" +
				"//4;1;1;1;c\n" +
				"//{gamedata}\n" +
				"//activeteam:@\n" +
				"//playedrounds:1\n" +
				"//maxrounds:5", false);
		// player on opened door - VALID!
		levels.put("" +
				"#######\n" +
				"#.m+###\n" +
				"#.....#\n" +
				"#####.#\n" +
				"#.....#\n" +
				"#++...#\n" +
				"#######\n" +
				"//{mobs}\n" +
				"//@;1;1;n;50;75;50;50;10\n" +
				"//Z;1;4;n;50;75;50;0;0\n" +
				"//{doors}\n" +
				"//4;1;1;1;o\n" +
				"//{gamedata}\n" +
				"//activeteam:@\n" +
				"//playedrounds:1\n" +
				"//maxrounds:5", true);
		// door on medikit
		levels.put("" +
				"#######\n" +
				"#.m+###\n" +
				"#.....#\n" +
				"#####.#\n" +
				"#.....#\n" +
				"#++...#\n" +
				"#######\n" +
				"//{mobs}\n" +
				"//@;1;1;n;50;75;50;50;10\n" +
				"//Z;1;4;n;50;75;50;0;0\n" +
				"//{doors}\n" +
				"//4;1;3;1;c\n" +
				"//{gamedata}\n" +
				"//activeteam:@\n" +
				"//playedrounds:1\n" +
				"//maxrounds:5", false);
		// door on ammo
		levels.put("" +
				"#######\n" +
				"#.m+###\n" +
				"#.....#\n" +
				"#####.#\n" +
				"#.....#\n" +
				"#++...#\n" +
				"#######\n" +
				"//{mobs}\n" +
				"//@;1;1;n;50;75;50;50;10\n" +
				"//Z;1;4;n;50;75;50;0;0\n" +
				"//{doors}\n" +
				"//4;1;2;1;c\n" +
				"//{gamedata}\n" +
				"//activeteam:@\n" +
				"//playedrounds:1\n" +
				"//maxrounds:5", false);
	}

	/**
	 * Test method for {@link de.tu_darmstadt.gdi1.xcom.tests.adapters.XcomTestAdapterLevel1#isCorrectLevel()}.
	 */
	@Test
	public final void testIsCorrectLevel() {
		for (String level : levels.keySet()) {
			//this.testAdapter.loadLevelFromString(level);
			assertEquals("Your implementation identified a correct level as incorrect "
					+ "or an incorrect level as correct.\n" + level + "\n", 
					levels.get(level), 
					Boolean.valueOf(this.testAdapter.isCorrectLevel(level)));
		}
	}
}
